{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Single Transmon - Grounded (xmon) \n",
    "\n",
    "We'll be creating a 2D design and adding a single transmon cross (xmon) qcomponent.\n",
    "\n",
    "Simple Metal Transmon Cross object. Creates the a cross-shaped island, the \"junction\" on the south end, and up to 3 connectors on the remaining arms (claw or gap).\n",
    "\n",
    "'claw_width' and 'claw_gap' define the width/gap of the CPW line that makes up the connector. Note, DC SQUID currently represented by single inductance sheet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# So, let us dive right in. For convenience, let's begin by enabling\n",
    "# automatic reloading of modules when they change.\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit_metal as metal\n",
    "from qiskit_metal import designs, draw\n",
    "from qiskit_metal import MetalGUI, Dict, open_docs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Each time you create a new quantum circuit design, \n",
    "# you start by instantiating a QDesign class. \n",
    "\n",
    "# The design class `DesignPlanar` is best for 2D circuit designs.\n",
    "\n",
    "design = designs.DesignPlanar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Launch Qiskit Metal GUI to interactively view, edit, and simulate QDesign: Metal GUI\n",
    "gui = MetalGUI(design)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### A transmon qubit\n",
    "You can create a ready-made transmon cross qubit from the QComponent Library, `qiskit_metal.qlibrary.qubits`. \n",
    "`transmon_cross.py` is the file containing our qubit so `transmon_cross` is the module we import. \n",
    "The `TransmonCross` class is our transmon cross qubit. Like all quantum components, `TransmonCross` inherits from `QComponent`. \n",
    "\n",
    " Connector lines can be added using the `connection_pads` dictionary. \n",
    " Each connector pad has a name and a list of default properties."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.transmon_cross import TransmonCross\n",
    "\n",
    "# Be aware of the default_options that can be overridden by user.\n",
    "TransmonCross.get_template_options(design)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "# The connectord_type can be string of '0' for 'Claw' or '1' for 'Gap' \n",
    "# to define which type of connector is used.\n",
    "\n",
    "# The connector_location can be string of '0', '90', '180'  degrees which of the three arms where a given connector should be.\n",
    "# South is for the junction. \n",
    "\n",
    "xmon_options = dict(\n",
    "    connection_pads=dict(\n",
    "        a = dict( connector_location = '0', connector_type = '0'), \n",
    "        b = dict(connector_location = '90', connector_type = '0'),\n",
    "        c = dict(connector_location = '180', connector_type = '1'),\n",
    "    ),\n",
    ")\n",
    "\n",
    "# Create a new Transmon Cross object with name 'Q1' \n",
    "q1 = TransmonCross(design, 'Q1', options=xmon_options)\n",
    "\n",
    "gui.rebuild()  # rebuild the design and plot \n",
    "gui.autoscale() #resize GUI to see QComponent\n",
    "gui.zoom_on_components(['Q1']) #Can also gui.zoom_on_components([q1.name])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# Let's see what the Q1 object looks like\n",
    "q1 #print Q1 information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Save screenshot as a .png formatted file.\n",
    "\n",
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "nbsphinx-thumbnail"
    ]
   },
   "outputs": [],
   "source": [
    "# Screenshot the canvas only as a .png formatted file.\n",
    "gui.figure.savefig('shot.png')\n",
    "\n",
    "from IPython.display import Image, display\n",
    "_disp_ops = dict(width=500)\n",
    "display(Image('shot.png', **_disp_ops))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## Closing the Qiskit Metal GUI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.main_window.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
